package cadad.org.parsers;

import org.htmlcleaner.TagNode;

import cadad.org.models.Item;

public class ItemParser {

	public Item parse(TagNode node) {

		Item item = new Item();

		if (node.getAttributeByName(ParserConstants.ID).equals(ParserConstants.TTABLE1)) {
			item.setType(ParserConstants.IDA);
		}

		if (node.getAttributeByName(ParserConstants.ID).equals(ParserConstants.TTABLE2)) {
			item.setType(ParserConstants.VUELTA);
		}

		String[] daysValue;

		daysValue = node.getText().toString().split(ParserConstants.MONEY_EUR);

		for (int i = 0; i < daysValue.length; i++) {
			String day = new String();
			day = daysValue[i];
			item.addDayToWeekAvailable(day);
		}

		return item;

	}

}
